-- ejercicio 1
doubleAll :: [Int] -> [Int]
doubleAll xs = [x * 2 | x <- xs]

doubleAll1 :: [Int] -> [Int]
doubleAll1 [] = []
doubleAll1 (x:xs) = (x*2) : doubleAll1 xs

doubleAll2 :: [Int] -> [Int]
doubleAll2 xs = map (*2) xs

doubleAll3 :: [Int] -> [Int]
doubleAll3 xs = map (2*) xs

-- ejercicio 2
uno :: Int -> Int
uno _ = 1

length_2 :: [Int] -> Int
length_2  = sum . map uno

-- ejercicio 3
addUp :: [Int] -> [Int]
addUp ns = filter greaterOne (map addOne ns)
	where
		greaterOne n = n > 1
		addOne n = n + 1

addUp1 :: [Int] -> [Int]
addUp1 ns = map addOne ( filter greaterCero ns)
	where
		greaterCero n = n > 0
		addOne n = n + 1
		
-- ejercicio 4
ejer4 :: [Int] -> [Int]
ejer4 ns = map addOne (map addOne ns)
	where
		addOne n = n + 1

ejer4_1 :: [Int] -> [Int]
ejer4_1 ns = map (addOne.addOne) ns
	where
		addOne n = n + 1

-- ejercicio 11
sumsquares :: [Int] -> Int
sumsquares xs = foldr (+) 0 (map (^2) xs)

-- ejercicio 14
mystery :: [a] -> [a]
mystery xs = foldr (++) [] (map sing xs )
	where 
		sing x = [x]
		
-- ejercicio 16
filterFirst :: (a -> Bool) -> [a] -> [a]
filterFirst p [] = []
filterFirst p (x:xs)
		| p x == False	= xs
		| otherwise 	= x : filterFirst p xs

-- ejercicio 9
total :: ( Int -> Int ) -> Int -> Int
total f n = foldr (+) 0 (map f [0..n])